/**
 * 铺满父祖级第一个 position = relative | absolute 的div容器
 */
import React from 'react';

const divRef = React.createRef();
export const FullDiv = (props: any) => {
    const { margin: m = 0 } = props;
    const { children, style, overflow = 'auto', position = 'absolute', top = m, left = m, right = m, bottom = m, margin, ...otherProps } = props;
    const fullStyle = { overflow, position, top, left, right, bottom };
    const handleChildren = () => {
        if (typeof children === 'function') {
            return children(divRef.current || {});
        }
        return children;
    }
    return <div ref={divRef} {...otherProps} style={{ ...fullStyle, ...style }}>{handleChildren()}</div>
}
export default FullDiv;
